#include <iostream>
using namespace std;

char* inverseWord(const char* str)
{
    int length = strlen(str);
    char* ret = new char[length];
    const char* current = str+length-1;
    const char* printEnd = current;
    const char* start = str;
    int retIndex = 0;
    while (current >= start) {
        if (' ' == *(current-1) || current == start) {
            //
            int i=0;
            while (current+i <= printEnd) {
                ret[retIndex] = *(current+i);
                ++i;
                ++retIndex;
            }
            if (current != start) {
                ret[retIndex] = ' ';
                ++retIndex;
                printEnd = current-2;
            }
            --current;
        }
        else {
            --current;
        }
    }
    return ret;
}

int main()
{
    char* inversedStr = inverseWord("Today is Thursday very good");
    cout << inversedStr << endl;
    //delete inversedStr;
}
